﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Library;

namespace QLKH.PopUp.Khachhang
{
    public partial class popXuly : Form
    {
        private Int64 idcus = -1;
        public popXuly(Int64 id)
        {
            InitializeComponent();
            idcus = id;
        }

        private void binCombo(ComboBox cb, DataTable dt, string name, string value, string option)
        {
            List<trangthai> list = new List<trangthai>();
            trangthai ls = null;
            ls = new trangthai();
            ls.name = option;
            ls.value = "0";
            list.Add(ls);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ls = new trangthai();
                    ls.name = dt.Rows[i][name].ToString();
                    ls.value = dt.Rows[i][value].ToString();
                    list.Add(ls);
                }
            }
            cb.DataSource = list;
            cb.DisplayMember = "name";
            cb.ValueMember = "value";
        }

        private void popXuly_Load(object sender, EventArgs e)
        {
            // hinh thuc
            clVipham clvp = new clVipham();
            DataTable dtvp = clvp.getxuly();
            binCombo(cbhtxl, dtvp, "ten", "id", "<< Chọn hình thức xử lý >>");
        }
        // khai báo 1 hàm delegate
        public delegate void AddXuLy(int id);
        // khai báo 1 kiểu hàm delegate
        public AddXuLy MyGetData;

        private void btsave_Click(object sender, EventArgs e)
        {
            if (MyGetData != null)
            {
                Int16 idxl = Int16.Parse((cbhtxl.SelectedValue == null) ? "0" : cbhtxl.SelectedValue.ToString());
                string noidung = txtnd.Text.Trim();
                Int64 ngay = Int64.Parse(dateday.Text.Trim().Split('/')[2].ToString() + dateday.Text.Trim().Split('/')[1].ToString() + dateday.Text.Trim().Split('/')[0].ToString());
                Int16 trangthai = 1;
                clVipham clvp = new clVipham();
                int outid = clvp.add(idcus, noidung, idxl, ngay, trangthai);
                MyGetData(outid);
            }
            this.Close();
        }

        private void btquit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
